home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: void main() and other atrocities!
- Date: 9 Feb 1996 12:02:02 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4fg97qINNnug@keats.ugrad.cs.ubc.ca>
- References: <4eduaj$1aq@grouper.Exis.Net> <9602021300.AA04359@dxmint.cern.ch> <4f2rahINNmud@keats.ugrad.cs.ubc.ca> <4f7ifv$8l4@airdmhor.gen.nz>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4f7ifv$8l4@airdmhor.gen.nz>,
- Simon Hosie <gumboot@airdmhor.gen.nz> wrote:
- >Kazimir Kylheku:
- >> It's also atrocious that main() has to be treated as a special language
- >> construct, and that a call to exit() in main() (when it is the last statement)
- >> is to be identical to a return.
- >
- > It's already a special case in that the program starts there.
- >
- >
- >> I did read the relevant section in the FAQ. It is merely concerned with the
- >> issue of eliminating compiler warnings stemming from calling exit() in main()
- >> despite a "void" declaration thereof. The issue that a void function may
- >> not be compatible with a call to an int function doesn't seem that significant,
- >> since nobody in their right mind would design a compiler that way.
- >
- > How about an operating system? Nah, they'd never make an operating system
- >that expected a return value from a program, would they?
-
- This is irrelevant since a program is not a C language function (under many
- operating systems). Try writing an assembly language program under Linux which
- terminates with a RET instruction. It will fail (even if you take care to pop
- the (argc, argv, envp) arguments off the stack first). There is nowhere within
- the address space of the process where it would even be reasonable to point a
- return address.
-
- The exit status (not "return value", as you call it) is explicitly passed back
- to the OS through the _exit system call trap, no other way. It has nothing to
- do with any particular programming language paradigm.
-
- If you set up your executable (under this particular OS) so that the
- machine-language entry point goes directly to your main() (or some other
- function), you would not be able to let the function "fall off" or attempt to
- return a value. You would have to make an explicit call to _exit().
-
- In this case, an appropriate declaration for main() would be to return "void".
- Doing so would not mean that you are not complying with the operating system's
- expectation to yield an exit status.
-
- What you are saying is a bit of a non sequitur, really. Most compilers do
- generate code that _won't_ break if you call an int declared function that was
- void defined (though you can't always count on it). Hence, declaring a void
- main(), while it is a transgression, is not a very serious error. On the other
- hand, most operating systems do allow or require a program to give an exit
- status, so perhaps your comment might have been worded as "Nah, they'd never
- make an operating system that _doesn't_ expect an exit status, would they?"
- since this is the less probable hypothesis.
- --
-
-